GuiItem Class
The base GuiItem that represents an element of a gui on the screen.
Constructor
GuiItem
-
texture -
interactive
Parameters:
-
textureTextureThe texture to set the sprite to
-
interactiveBooleanWhether this item should repsond to mouse events
Item Index
Methods
Properties
Methods
addAnimation
-
name -
frames -
[speed] -
[loop]
Adds a new animation to this animated sprite
Parameters:
-
nameStringThe string name of the animation
-
framesArrayThe array of texture frames
-
[speed]Number optionalThe animation speed
-
[loop]Boolean optionalLoop the animation or not
Returns:
Returns itself.
clone
()
Sprite
Creates a new Sprite instance with the same values as this one
Returns:
Returns the new sprite
destroy
()
Removes this sprite from the stage and the physics system
disablePhysics
-
callback
Disbales physics for this sprite
Parameters:
-
callbackFunctionThe callback function to call after physics have been disabled
Returns:
Returns itself.
emit
-
type -
data
Emits an event which will run all registered listeners for the event type
Parameters:
-
typeStringThe event name to emit
-
dataMixedAny data you want passed along with the event
Returns:
Returns itself.
enablePhysics
-
system -
callback
Enables physics for this sprite
Parameters:
-
systemPhysicsSystemThe system for the sprite to be in
-
callbackFunctionThe callback function to call after physics have been enabled
Returns:
Returns itself.
goto
-
frame -
[name]
Goes to a frame and starts playing the animation from there. You can optionally pass the name of a new aniamtion to start playing.
Parameters:
-
frameNumberThe index of the frame to start on
-
[name]String optionalThe string name of the animation to go to
Returns:
Returns itself.
mousedown
-
evt
Function that is called whenever a mousedown event occurs. This is used to handle dragging for GUI items.
Parameters:
-
evtInteractionEventThe interaction event
mousemove
-
evt
Function that is called whenever a mousemove event occurs. This is used to handle dragging for GUI items.
Parameters:
-
evtInteractionEventThe interaction event
mouseup
-
evt
Function that is called whenever a mouseup event occurs. This is used to handle dragging for GUI items.
Parameters:
-
evtInteractionEventThe interaction event
off
-
type -
listener
Removes a listener function for an event type
Parameters:
-
typeStringThe event name to emit
-
listenerFunctionThe function to remove
Returns:
Returns itself.
on
-
type -
listener
Registers a listener function to be run on an event occurance
Parameters:
-
typeStringThe event name to listen for
-
listenerFunctionThe function to execute when the event happens
Returns:
Returns itself.
once
-
type -
listener
Registers a one-time callback for an event
Parameters:
-
typeStringThe event name to listen for
-
listenerFunctionthe callback to call when the event occurs
Returns:
Returns itself.
play
()
Sprite
chainable
Starts playing the currently active animation
Returns:
Returns itself.
setMass
-
mass
Sets the mass of this sprite
Parameters:
-
massNumberThe new mass of the object
Returns:
Returns itself.
setPosition
-
x -
y
Sets the position of this sprite
Parameters:
-
xNumber | VectorThe x coord to set position to, if a Vector is passed the y param is ignored
-
yNumberThe y coord to set position to
Returns:
Returns itself.
setRotation
-
rotation
Sets the rotation of this sprite
Parameters:
-
rotationNumberThe new rotation of the object in radians
Returns:
Returns itself.
setVelocity
-
x -
y
Sets the velocity of this sprite
Parameters:
-
xNumber | VectorThe x coord to set the velocity to, if a Vector is passed the y param is ignored
-
yNumberThe y coord to set the velocity to
Returns:
Returns itself.
stop
()
Sprite
chainable
Stops playing the currently active animation
Returns:
Returns itself.
updateTransform
()
private
Called by PIXI to update our textures and do the actual animation
Properties
_phys
Object
private
The physics namespace that all physics properties go into. Those properties are:
- system {PhysicsSystem} PhysicsSystem that this object is a part of.
- active {Boolean} Whether or not this target is actively having physics simulated.
Default: {}
_velocity
Vector
private
The internal velocity value, used as a reusable vector for the setVelocity function. Setting this directly has no effect.
animations
Object
The registerd animations for this AnimatedSprite
currentAnimation
String
The currently playing animation
currentFrame
Number
The current frame being shown
draggable
Boolean
Sets whether or not you can drag the GuiItem around
Default: false
dragging
Object
Describes if the current item is being dragged or not, if it is this object will hold the last local position of the mouse (relative to this object's parent)
Default: false
inertia
Number
The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)
Default: 0
lifetime
Number
private
The lifetime of the sprite. Once it reaches 0 (after being set) the sprite's visible property is set to false, so that it will no longer be rendered. NOT YET IMPLEMENTED
Default: Infinity
loop
Boolean
Whether or not to loop the animations. This can be overriden on a per-animation level
Default: false
mass
Number
The mass of this object, please use setMass to set this value
Default: 0
name
String
The name of the sprite
Default: ''
playing
Boolean
Whether or not the animation is currently playing
speed
Number
The animation speed for this sprite
Default: 1
Events
click
A callback that is used when the users clicks on the sprite with their mouse
Event Payload:
-
interactionDataInteractionData
collision
On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
complete
Fired when the running animation completes
Event Payload:
-
animationStringThe animation that has completed
frame
Fired when a new frame of the running animation is shown
Event Payload:
-
animationStringThe animation name that is playing
-
frameIdNumberThe frame that is being shown
mousedown
A callback that is used when the user clicks the mouse down over the sprite
Event Payload:
-
interactionDataInteractionData
mousemove
A callback that is used when the user moves the mouse while over the sprite
Event Payload:
-
interactionDataInteractionData
mouseout
A callback that is used when the users mouse leaves the sprite
Event Payload:
-
interactionDataInteractionData
mouseover
A callback that is used when the users mouse rolls over the sprite
Event Payload:
-
interactionDataInteractionData
mouseup
A callback that is used when the user releases the mouse that was over the sprite for this callback to be fired the mouse must have been pressed down over the sprite
Event Payload:
-
interactionDataInteractionData
mouseupoutside
A callback that is used when the user releases the mouse that was over the sprite but is no longer over the sprite for this callback to be fired, The touch must have started over the sprite
Event Payload:
-
interactionDataInteractionData
separate
On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
Event Payload:
-
objSpriteColliding sprite
-
colShapecp.ShapeThe colliding physics shape
-
myShapecp.ShapeYour physics shape that caused the collision
tap
A callback that is used when the users taps on the sprite with their finger basically a touch version of click
Event Payload:
-
interactionDataInteractionData
touchend
A callback that is used when the user releases a touch over the sprite
Event Payload:
-
interactionDataInteractionData
touchendoutside
A callback that is used when the user releases the touch that was over the sprite for this callback to be fired, The touch must have started over the sprite
Event Payload:
-
interactionDataInteractionData
touchstart
A callback that is used when the user touch's over the sprite
Event Payload:
-
interactionDataInteractionData